from selenium import webdriver
from unittest import TestCase
from ddt import ddt,data,unpack
from 测试数据.Testnum1 import Testnumber
from 页面对象.LoanPage import LoginPage

@ddt
class TestLoan(TestCase):
    @data(*Testnumber().excel3_1)
    @unpack
    def testLoan(self,username,password,balance,money,time,expect):
        driver = webdriver.Chrome()
        driver.maximize_window()
        driver.get("http://192.168.139.128:90/")
        driver.implicitly_wait(10)
        login = LoginPage(driver)

        result =login.login(username, password, money, time)


        # if result!=expect:
        #     driver.save_screenshot(username+password+".png")
        driver.quit()
        self.assertEqual(expect,result)

    @data(*Testnumber().excel3_3)
    @unpack
    def testLoan3(self, username, password, balance, money, time, expect):
        driver = webdriver.Chrome()
        driver.maximize_window()
        driver.get("http://192.168.139.128:90/")
        driver.implicitly_wait(10)
        login = LoginPage(driver)

        result = login.login3(username, password, money, time)

        # if result!=expect:
        #     driver.save_screenshot(username+password+".png")
        driver.quit()
        self.assertEqual(expect, result)


    @data(*Testnumber().excel3_2_1)
    @unpack
    def testLoan2(self, username, password, balance, money, time, expect):
        driver = webdriver.Chrome()
        driver.maximize_window()
        driver.get("http://192.168.139.128:90/")
        driver.implicitly_wait(10)
        login = LoginPage(driver)

        result = login.login2_1(username, password, money, time)
        driver.quit()
        driver = webdriver.Chrome()
        driver.maximize_window()
        driver.get("http://192.168.139.128:90/")
        driver.implicitly_wait(10)
        login = LoginPage(driver)

        login.login2_2()

        driver.quit()
        driver = webdriver.Chrome()
        driver.maximize_window()
        driver.get("http://192.168.139.128:90/")
        driver.implicitly_wait(10)
        login = LoginPage(driver)

        expect = login.login2_3(username, password)
        # if result!=expect:
        #     driver.save_screenshot(username+password+".png")
        driver.quit()
        expect=float(expect[5:-1])
        result=float(result[5:-1])
        result=result+10000
        self.assertEqual(expect, result)
